package com.newtouch.bxzs.enterprise.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.enterprise.model.bo.CustomerInventoryBO;
import com.newtouch.bxzs.enterprise.model.vo.ActivityCustomerInventoryVO;
import com.newtouch.bxzs.enterprise.model.vo.ActivityDetailVO;
import com.newtouch.bxzs.enterprise.model.vo.ConferenceCustomerInventoryVO;
import com.newtouch.bxzs.enterprise.model.vo.ConferenceDetailVO;
import com.newtouch.bxzs.enterprise.service.CustomerInventoryService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 大数据客户清单接口调用ServiceImpl类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/17 13:57</td>
 * <td>dingqianbin</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author dingqianbin
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class CustomerInventoryServiceImpl implements CustomerInventoryService {

    private static final Log logger = LogFactory.getLog(CustomerInventoryServiceImpl.class);

    @Autowired
    RedisUtils redisUtils;

    @Override
    public List<CustomerInventoryBO> getConferenceCustomerInventory(Integer batch, ConferenceDetailVO conferenceDetailVO) {
        ConferenceCustomerInventoryVO conferenceCustomerInventoryVO = new ConferenceCustomerInventoryVO();
        conferenceCustomerInventoryVO.setBatch(batch);
        conferenceCustomerInventoryVO.setConferenceDetailVO(conferenceDetailVO);
        SendHttpRequestUtils<ConferenceCustomerInventoryVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
        List<CustomerInventoryBO> customerInventoryBOList;
        customerInventoryBOList = JSONObject.parseArray(sendHttpRequestUtils.sendHttpRequestToArray(conferenceCustomerInventoryVO,
                redisUtils.get(SystemParamsEnum.MARKETING_CONFERENCE_BIG_DATA_CUSTOMER_LIST.getCode())).toJSONString(),CustomerInventoryBO.class);
        logger.info("获取营销会议大数据客户清单成功");
        return customerInventoryBOList;
    }

    @Override
    public List<CustomerInventoryBO> getActivityCustomerInventory(Integer batch, ActivityDetailVO activityDetailVO) {
        ActivityCustomerInventoryVO activityCustomerInventoryVO = new ActivityCustomerInventoryVO();
        activityCustomerInventoryVO.setBatch(batch);
        activityCustomerInventoryVO.setActivityDetailVO(activityDetailVO);
        SendHttpRequestUtils<ActivityCustomerInventoryVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
        List<CustomerInventoryBO> customerInventoryBOList;
        customerInventoryBOList = JSONObject.parseArray(sendHttpRequestUtils.sendHttpRequestToArray(activityCustomerInventoryVO,
                redisUtils.get(SystemParamsEnum.MARKETING_ACTIVITY_BIG_DATA_CUSTOMER_LIST.getCode())).toJSONString(),CustomerInventoryBO.class);
        logger.info("获取营销活动大数据客户清单成功");
        return customerInventoryBOList;
    }
}
